﻿using PracticeCentre.Common;
using PracticeCentre.DataControl;
using PracticeCentre.Modeles;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PracticeCentre.Business
{
    public class Recuritselect
    {
        public PageModel<AddressView> GetPlanList(PageModel<AddressView> page)
        {
            DataControlHelper dataHelper = new DataControlHelper();
            try
            {
                string sc = "  AddressView.PlanState=0 and AddressView.PlanPeriod=";
                if (page.Where == "0")
                {
                    sc += " '月度计划'";
                }
                else if (page.Where == "1")
                {
                    sc += " '季度计划'";
                }
                else if (page.Where == "2")
                {
                    sc += " '年度计划'";
                }
                SqlParameter[] parameters = new SqlParameter[] {
                    new SqlParameter("@sys_PageIndex",page.PageNumber),
                    new SqlParameter("@sys_PageSize",page.PageSize),
                    new SqlParameter("@sys_Table","AddressView"),
                    new SqlParameter("@sys_Key","ID"),
                    new SqlParameter("@sys_Where",sc),
                    new SqlParameter("@sys_Order","ID"),
                    new SqlParameter("@sys_AscOrDesc","Desc"),
                    new SqlParameter("@pageCount",page.PageCount),
                    new SqlParameter("@recordCount",page.RowCount)
                };
                parameters[7].Direction = ParameterDirection.Output;
                parameters[8].Direction = ParameterDirection.Output;
                int pagecount = 0;
                int rowcount = 0;
                DataTable dt = dataHelper.ExecuteDataTable<AddressView>(ProceduresConfig.GeneralPaging, out pagecount, out rowcount, parameters);
                DataModelHandler<AddressView> dataHandler = new DataModelHandler<AddressView>();
                List<AddressView> postList = dataHandler.FillModel(dt);
                page.PageCount = pagecount;
                page.RowCount = rowcount;
                page.DataList = postList;
                return page;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
